import {
	EnumActionType
} from './action-type';
//数据
const state = {
	dat: '模块2',
	actionType: EnumActionType,
	action: '',
	editDom: null,
	editNode: null,
	editRect: {
		t: 0,
		l: 0,
		w: 0,
		h: 0
	},
};

//get访问器
const getters = {
	dat: (state) => (par) => {
		return state.dat;
	},
	editDom: (state) => state.editDom,
	editNode: (state) => state.editNode,
	editRect: (state) => state.editRect,
};

//异步
const actions = {
	asyncFn(state, t) {
		state.dispatch("asyncFn2", '测试');
		state.commit("hFn", '数据');
	},
	asyncFn2(state, t) {
		console.log("数据2", t);
	},
};

//
const mutations = {
	hFn(state, v) {
		state.v = v;
	},
	hEditNode(state, node) {
		state.editNode = node;
		let d = node.dom;

		state.editRect = {
			t: d.offsetTop,
			l: d.offsetLeft,
			w: d.clientWidth,
			h: d.clientHeight
		};
		state.editDom = d;
		//console.log("设置dom", node.dom);
	},
	hRectChange(state, d) {
		// let r = state.editRect;
		// if (r.t == d.t && r.l == d.l && r.w == d.w && r.h == d.h) {
		// 	return;
		// }
		console.log("change:",d);
		state.editRect = d;
	}
}

/**vuex中的store分模块管理
		在store的index.js中引入各个模块
		namespaced:true，解决不同模块命名冲突的问题
		
		在不同页面中引入getter、actions、mutations时，需要加上所属的模块名
		export default new Vuex.Store({
			modules:{
        mod2 //模块
			}
		});
		export default createStore({
			modules:{
			  mod2//模块2				
			}
		});
		
		store.dispatch("mod2/asyncFn","异步查询数据");		 
		store.commit("mod2/hFn","同步修改数据");
		store.getters["mod2/dat"]("获取数据")
*/

export default {
	namespaced: true,
	state,
	getters,
	actions,
	mutations
}
